package com.yex.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yex.common.utils.PageUtils;
import com.yex.dao.BankListDao;
import com.yex.entity.BankListEntity;
import com.yex.service.BankListService;
import com.yex.service.LocaleMessageSourceService;
import com.yex.service.OrderBankService;
import com.yex.utils.JsonResultVo;
import com.yex.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("bankListService")
public class BankListServiceImpl extends ServiceImpl<BankListDao, BankListEntity> implements BankListService {
    @Autowired
    private LocaleMessageSourceService message;
    @Autowired
    private OrderBankService orderBankService;

    @Override
    public PageUtils queryPage(Map<String, Object> params, String filter) {
        Page<BankListEntity> page = new Query<BankListEntity>(params).getPage();
        List<BankListEntity> bankListEntityList = baseMapper.selectPageFilter(page, filter);
        page.setRecords(bankListEntityList);
        return new PageUtils(page);
    }

    @Override
    public JsonResultVo selectBankList() {
        Map<String, Object> mapParams = new HashMap<>(2);
        mapParams.put("status", "1");
        List<BankListEntity> bankListEntityList = baseMapper.selectByMap(mapParams);

        List<Map<String, Object>> bankList = new ArrayList<>();
        for (BankListEntity bankListEntity : bankListEntityList) {
            Map<String, Object> map = new HashMap<>(2);
            map.put("id", bankListEntity.getId());
            map.put("name", bankListEntity.getTitle());
            bankList.add(map);
        }

        return new JsonResultVo(message.getMessage("success"), bankList, 0);
    }

    @Override
    public BankListEntity findById(Integer bankType) {
        EntityWrapper<BankListEntity> wrapper = new EntityWrapper<>();
        wrapper.eq("id", bankType).eq("status", 1);
        List<BankListEntity> bankListEntities = baseMapper.selectList(wrapper);
        if (bankListEntities == null || bankListEntities.size() == 0) return null;
        return bankListEntities.get(0);
    }
}
